<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='global-property-'>/**
</span> * @ignore
 * delegate events for children
 * @author yiminghe@gmail.com
 */
KISSY.add(&quot;component/extension/delegate-children&quot;, function (S, Node, Manager) {

    var UA = S.UA,
        ie = S.Env.host.document.documentMode || UA.ie,
        Features = S.Features,
        Gesture = Node.Gesture,
        isTouchEventSupported = Features.isTouchEventSupported();

    function onRenderChild(e) {
        if (e.target == this) {
            var child = e.component,
                el = child.$el;
            el.addClass(this.__childClsTag);
        }
    }

    function onRemoveChild(e) {
        if (e.target == this) {
            var child = e.component,
                el = child.$el;
            if (el) {
                el.removeClass(this.__childClsTag);
            }
        }
    }

<span id='KISSY-Component-Extension-DelegateChildren'>    /**
</span>     * delegate events for component's children. for mixin.
     * @class KISSY.Component.Extension.DelegateChildren
     */
    function DelegateChildren() {
        var self = this;
        self.__childClsTag = S.guid('ks-component-child');
        self.on('afterRenderChild', onRenderChild, self)
            .on('afterRemoveChild', onRemoveChild, self);
    }

    S.augment(DelegateChildren, {
        handleChildrenEvents: function (e) {
            if (!this.get(&quot;disabled&quot;)) {
                var control = this.getOwnerControl(e);
                if (control &amp;&amp; !control.get(&quot;disabled&quot;)) {
                    e.stopPropagation();
                    // Child control identified; forward the event.
                    switch (e.type) {
                        case Gesture.start:
                            control.handleMouseDown(e);
                            break;
                        case Gesture.end:
                            control.handleMouseUp(e);
                            break;
                        case Gesture.tap:
                            control.handleClick(e);
                            break;
                        case &quot;mouseenter&quot;:
                            control.handleMouseEnter(e);
                            break;
                        case &quot;mouseleave&quot;:
                            control.handleMouseLeave(e);
                            break;
                        case &quot;contextmenu&quot;:
                            control.handleContextMenu(e);
                            break;
                        case &quot;dblclick&quot;:
                            control.handleDblClick(e);
                            break;
                        default:
                            S.error(e.type + &quot; unhandled!&quot;);
                    }
                }
            }
        },

        __bindUI: function () {
            var self = this,
                events = Gesture.start +
                    &quot; &quot; + Gesture.end +
                    &quot; &quot; + Gesture.tap;

            if (Gesture.cancel) {
                events += ' ' + Gesture.cancel;
            }

            if (!isTouchEventSupported) {
                events += &quot; mouseenter mouseleave contextmenu &quot; +
                    (ie &amp;&amp; ie &lt; 9 ? &quot;dblclick &quot; : &quot;&quot;);
            }

            self.$el.delegate(events, '.' + self.__childClsTag,
                self.handleChildrenEvents, self);
        },

<span id='KISSY-Component-Extension-DelegateChildren-method-getOwnerControl'>        /**
</span>         * Get child component which contains current event target node.
         * @protected
         * @param {KISSY.Event.DomEvent.Object} e event
         * @return {KISSY.Component.Control}
         */
        getOwnerControl: function (e) {
            return Manager.getComponent(e.currentTarget.id);
        }
    });

    return DelegateChildren;
}, {
    requires: ['node', 'component/manager']
});</pre>
</body>
</html>
